package cn.com.nes.site.entity.em.crm.saleorder;

import cn.com.nes.common.exception.NoSuchEnumException;

import java.util.HashMap;
import java.util.Map;

/**
 * 销售单状态 枚举
 * 值域对应 t_param 表 param_type = 302
 */
public enum SaleOrderStatusEnum {
    ABANDONED(-1, "废单"),
    USER_CONFIRMED(0, "用户待确认"),
    TO_BE_PAID(1, "待支付"),
    PAID_SUCCESS(2, "支付成功"),
    PAID_FAILED(3, "支付失败"),
    CANCEL(4, "取消订单")
    ;

    private Integer key;

    private String value;

    SaleOrderStatusEnum(Integer key, String value) {
        this.key = key;
        this.value = value;
    }

    public Integer getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    public static SaleOrderStatusEnum getEnum(String key) {
        Map<String, SaleOrderStatusEnum> map = new HashMap<>();
        for (SaleOrderStatusEnum saleOrderStatusEnum : values()) {
            map.put(String.valueOf(saleOrderStatusEnum.getKey()), saleOrderStatusEnum);
        }
        if (!map.containsKey(key)) {
            throw new NoSuchEnumException("未匹配的销售单状态");
        }
        return map.get(String.valueOf(key));
    }
}
